#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        vector<pair<int, int>> inter;
        for (auto& in : intervals) inter.push_back({ in[0], in[1] });
        sort(inter.begin(), inter.end());
        vector<vector<int>> ret;
        vector<int> tmp;
        tmp.push_back(inter[0].first), tmp.push_back(inter[0].second);
        ret.push_back(tmp);
        for (int i = 1; i < inter.size(); i++)
        {
            int n = ret.size() - 1;
            if (ret[n][1] >= inter[i].first) ret[n][1] = max(ret[n][1], inter[i].second);
            else
            {
                vector<int> tmp;
                tmp.push_back(inter[i].first), tmp.push_back(inter[i].second);
                ret.push_back(tmp);
            }
        }
        return ret;
    }
};